home *** CD-ROM | disk | FTP | other *** search
/ CD Concept 6 / CD Concept 06.iso / mac / UTILITAIRE / Little Smalltalk v3.1.4 / C Source / Sources / glue2.cp < prev    next >
Text File  |  1995-01-26  |  23KB  |  777 lines

  1. /*
  2.     Little Smalltalk, version 3
  3.     Written by Tim Budd, Oregon State University, June 1988
  4.  
  5.     Symantec Think Class Library interface code 
  6.         ⌐Julian Barkway, April 1994, all rights reserved.
  7.     
  8.     glue2.cp 
  9.     --------
  10.     
  11.     This is the interface between Little Smalltalk and the Symantec Think 
  12.     Class Library (v1.1.3). Where possible, I have retained the StdWin 
  13.     function names and parameters used in the original Little Smalltalk (v3) 
  14.     (although certain structures now refer to TCL objects) in order to assist 
  15.     porting. 
  16.     
  17.     Glue1.cp contains functions relating to windows, menus, graphics and dialogues.
  18.     Glue2.cp contains text, event handling and general purpose functions.
  19. */
  20.  
  21. #include <string.h>
  22. #include "env.h"
  23. #include "memory.h"
  24. #include "macio.h"
  25.  
  26. #undef class
  27. #include "Constants.h"
  28. #include "CDataFile.h"
  29. #include "CGraphicsPane.h"
  30. #include "CTextPane.h"
  31. #include "CSelectPane.h"
  32. #include "CLStWindow.h"
  33. #include "CLStApp.h"
  34. #include "CLStSwitchboard.h"
  35. #include "CLStScrollPane.h"
  36. #include "LStResources.h"
  37. #include "glue.h"
  38.  
  39. extern short        gClicks;
  40. extern CLStApp        *gSmalltalk;
  41.  
  42. #define uchar    unsigned char        // Just laziness :-)
  43.  
  44.  
  45. //===================================================================================
  46. // Set the font in the given TextEdit to the font specified in fontName.
  47. // Not a StdWin function.
  48. //===================================================================================
  49. void setFont (TEXTEDIT *tp, char *fontName)
  50. {
  51.     Str255    str;
  52.     Rect    margin = {0, 0, 0, 0};
  53.     
  54.     strcpy ((char *)str, fontName);
  55.     CtoPstr ((char *)str);
  56.     ((CTextPane *)tp)->SetFontName (str);
  57.                             // Force a dummy re-size which will re-calculate number 
  58.                             // of complete lines available, thereby ensuring that 
  59.                             // the last line doesn't get clipped vertically.
  60.     ((CTextPane *)tp)->ResizeFrame  (&margin);
  61.     ((CTextPane *)tp)->AdjustBounds ();    
  62. }
  63.  
  64.  
  65. //===================================================================================
  66. // Set the font size in the given TextEdit to that specified by fontSize.
  67. // Not a StdWin function.
  68. //===================================================================================
  69. void setFontSize (TEXTEDIT *tp, short fontSize)
  70. {
  71.     Rect    margin = {0, 0, 0, 0};
  72.     
  73.     ((CTextPane *)tp)->SetFontSize  (fontSize);
  74.     ((CTextPane *)tp)->ResizeFrame  (&margin);
  75.     ((CTextPane *)tp)->AdjustBounds ();    
  76. }
  77.  
  78.  
  79. //===================================================================================
  80. // Set the type face in the given TextEdit to that specified by typeFace.
  81. //
  82. // Note that in Smalltalk the following faces are available:
  83. //        1 - plain, 
  84. //        2 - bold, 
  85. //        3 - italic, 
  86. //        4 - underline
  87. //
  88. // and are specified by the numbers given NOT the Mac system constants.
  89. //
  90. // Not a StdWin function.
  91. //===================================================================================
  92. void setTypeFace (TEXTEDIT *tp, short typeFace)
  93. {
  94.     Rect    margin = {0, 0, 0, 0};
  95.     
  96.     switch (typeFace) {
  97.         case 1:
  98.             typeFace = normal;
  99.             break;
  100.         case 2:
  101.             typeFace = bold;
  102.             break;
  103.         case 3:
  104.             typeFace = italic;
  105.             break;
  106.         case 4:
  107.             typeFace = underline;
  108.             break;
  109.         default:
  110.             typeFace = normal;
  111.     }
  112.     ((CTextPane *)tp)->SetFontStyle (typeFace);
  113.     ((CTextPane *)tp)->ResizeFrame  (&margin);
  114.     ((CTextPane *)tp)->AdjustBounds ();
  115. }
  116.  
  117.  
  118. //===================================================================================
  119. // Replace the currently selected text in the given TextEdit by the text specified.
  120. //===================================================================================
  121. void tereplace (TEXTEDIT *tp, char *str)
  122. {
  123.     short        i;
  124.     long        selStart, selEnd;
  125.     TEHandle    teh = ((CTextPane *)tp)->macTE;
  126.     
  127.     for (i = 0; i < strlen (str); i++)    // Convert all LFs to CRs
  128.         if (str [i] == '\n')            // -- probably unnecessary in majority of cases.
  129.             str [i] = '\r';
  130.             
  131.     ((CTextPane *)tp)->GetSelection (&selStart, &selEnd);
  132.  
  133.     if (selEnd > selStart) {
  134.         ((CTextPane *)tp)->SetSelection (selEnd, selEnd, FALSE);
  135.     }
  136.  
  137.     ((CTextPane *)tp)->InsertTextPtr ((Ptr)str, (long)strlen (str), TRUE);
  138.     ((CTextPane *)tp)->AdjustBounds ();
  139. }
  140.  
  141.  
  142. //===================================================================================
  143. // Replace all the text in a text pane with the given text. Not a StdWin function.
  144. //===================================================================================
  145. void replaceAllText (TEXTEDIT *tp, char *str)
  146. {
  147.     short        i;
  148.     
  149.     for (i = 0; i < strlen (str); i++)            // Convert all LFs to CRs
  150.         if (str [i] == '\n')
  151.             str [i] = '\r';
  152.             
  153.     ((CTextPane *)tp)->ReplaceContents (str);
  154.     ((CTextPane *)tp)->AdjustBounds ();
  155. }
  156.  
  157.  
  158. //===================================================================================
  159. // Delete all the text in a text pane. Not a StdWin function.
  160. //===================================================================================
  161. void deleteAllText (TEXTEDIT *tp)
  162. {
  163.     ((CTextPane *)tp)->DeleteContents ();
  164.     ((CTextPane *)tp)->AdjustBounds ();
  165. }
  166.  
  167.  
  168. //===================================================================================
  169. // Return current size of pane. Not a StdWin function.
  170. //===================================================================================
  171. void getPaneSize (TEXTEDIT *tp, short *width, short *height)
  172. {
  173.     long    w, h;
  174.     
  175.     ((CPane *)tp)->GetPixelExtent (&w, &h);
  176.     *width  = (short)w;
  177.     *height = (short)h;
  178. }
  179.  
  180.  
  181. #define getSizingOptions(x,y,x1,y1)    if (x)                     \
  182.                                         x1 = sizELASTIC;    \
  183.                                     else                    \
  184.                                         x1 = sizFIXEDLEFT;    \
  185.                                     if (y)                    \
  186.                                         y1 = sizELASTIC;    \
  187.                                     else                    \
  188.                                         y1 = sizFIXEDLEFT
  189.  
  190. //===================================================================================
  191. // Add a basic pane to a window - not a StdWin function.
  192. //===================================================================================
  193. TEXTEDIT *addScrollPane (WINDOW *win, short left, short top, short right, short bottom,
  194.                             short horizOption, short vertOption)
  195. {
  196.     CLStScrollPane    *scrollPane;
  197.     short            w = right - left,
  198.                     h = bottom - top;
  199.  
  200.     scrollPane = new (CLStScrollPane);
  201.     scrollPane->IScrollPane ((CLStWindow *)win->window, (CDocument *)(win->document),
  202.                              w, h, left, top,
  203.                              (SizingOption)horizOption, (SizingOption)vertOption, 
  204.                              TRUE, TRUE, TRUE);
  205.     return (char *)scrollPane;
  206. }
  207.  
  208.  
  209. //===================================================================================
  210. // Add a selection pane to a window - not a StdWin function.
  211. //===================================================================================
  212. TEXTEDIT *addSelPane (WINDOW *win, short left, short top, short right, short bottom,
  213.                        short horizElastic, short vertElastic, short lineLength)
  214. {
  215.     CSelectPane        *selPane;
  216.     CLStScrollPane    *scrollPane;
  217.     LongPt            origin   = {0L, 0L};
  218.     SizingOption    horizOption,  vertOption;
  219.  
  220.     getSizingOptions (horizElastic, vertElastic, horizOption, vertOption);
  221.     scrollPane = (CLStScrollPane *)addScrollPane (win, left, top, right, bottom, 
  222.                                                   horizOption, vertOption);
  223.     selPane = new (CSelectPane);
  224.     selPane->ISelectPane (scrollPane, (CDocument *)(win->document), 
  225.                           horizOption, vertOption, lineLength);
  226.     ((CDocument *)(win->document))->itsMainPane = selPane;
  227.     ((CDocument *)(win->document))->itsGopher   = selPane;
  228.  
  229.     scrollPane->InstallPanorama (selPane);
  230.     selPane->ScrollTo   (&origin, TRUE);        // Ensure everything is visible
  231.     
  232.     return (char *)selPane;
  233. }
  234.  
  235.  
  236. //===================================================================================
  237. // Add a text pane to a window
  238. //===================================================================================
  239. TEXTEDIT *addTextPane (WINDOW *win, short left, short top, short right, short bottom,
  240.                        short horizElastic, short vertElastic, short lineLength)
  241. {
  242.     CTextPane        *textPane;
  243.     CLStScrollPane    *scrollPane;
  244.     LongPt            origin   = {0L, 0L};
  245.     SizingOption    horizOption,  vertOption;
  246.  
  247.     getSizingOptions (horizElastic, vertElastic, horizOption, vertOption);
  248.     scrollPane = (CLStScrollPane *)addScrollPane (win, left, top, right, bottom, 
  249.                                                   horizOption, vertOption);
  250.     textPane = new (CTextPane);
  251.     textPane->ITextPane (scrollPane, (CDocument *)(win->document), 
  252.                          horizOption, vertOption, lineLength);
  253.     ((CDocument *)(win->document))->itsMainPane = textPane;
  254.     ((CDocument *)(win->document))->itsGopher   = textPane;
  255.  
  256.     scrollPane->InstallPanorama (textPane);
  257.     textPane->ScrollTo   (&origin, TRUE);        // Ensure everything is visible
  258.     
  259.     return (char *)textPane;
  260. }
  261.  
  262.  
  263. //===================================================================================
  264. // Stub function provided for StdWin compatibility.
  265. //===================================================================================
  266. TEXTEDIT *tecreate (WINDOW *win, int left, int top, int right, int bottom)
  267. {
  268.     return addTextPane (win, left, top, right, bottom, TRUE, TRUE, 2000);
  269. }
  270.  
  271.  
  272. //===================================================================================
  273. // Add a graphics pane to a window
  274. //===================================================================================
  275. TEXTEDIT *addGraphicsPane (WINDOW *win, short left, short top, short right, short bottom,
  276.                            short horizElastic, short vertElastic)
  277. {
  278.     CGraphicsPane    *gPane;
  279.     CLStScrollPane    *scrollPane;
  280.     LongPt            origin   = {0L, 0L};
  281.     SizingOption    horizOption,  vertOption;
  282.  
  283.     getSizingOptions (horizElastic, vertElastic, horizOption, vertOption);
  284.     scrollPane = (CLStScrollPane *)addScrollPane (win, left, top, right, bottom, 
  285.                                                   horizOption, vertOption);
  286.     gPane = new (CGraphicsPane);
  287.     gPane->IGraphicsPane (scrollPane, (CDocument *)(win->document), 
  288.                          horizOption, vertOption);
  289.     ((CDocument *)(win->document))->itsMainPane = gPane;
  290.     ((CDocument *)(win->document))->itsGopher   = gPane;
  291.  
  292.     scrollPane->InstallPanorama (gPane);
  293.     gPane->ScrollTo   (&origin, TRUE);        // Ensure everything is visible
  294.     
  295.     return (char *)gPane;
  296. }
  297.  
  298.  
  299. //===================================================================================
  300. // Stub function provided for StdWin compatibility.
  301. //===================================================================================
  302. Boolean teevent (TEXTEDIT *tp, EVENT *e)
  303. {
  304.     return FALSE;
  305. }
  306.  
  307.  
  308. //===================================================================================
  309. // Scroll the text, if necessary, to ensure that the selected area is visible in the
  310. // text pane.
  311. //===================================================================================
  312. void scrollToSelection (TEXTEDIT *tp)
  313. {
  314.     ((CTextPane *)tp)->ScrollToSelection ();
  315. }
  316.  
  317.  
  318. //===================================================================================
  319. // Set the text selection to the given character positions.
  320. //===================================================================================
  321. void setTextSelection (TEXTEDIT *tp, long startPos, long endPos)
  322. {
  323.     ((CTextPane *)tp)->SetSelection (startPos, endPos, TRUE);
  324. }
  325.  
  326.  
  327. //===================================================================================
  328. // Return the start and end character positions of the current text selection.
  329. //===================================================================================
  330. void getTextSelection (TEXTEDIT *tp, long *startPos, long *endPos)
  331. {
  332.     ((CTextPane *)tp)->GetSelection (startPos, endPos);
  333. }
  334.  
  335.  
  336. //===================================================================================
  337. // tegettext - return all the text associated with the current TE.
  338. //===================================================================================
  339.  
  340. #define MAXBUF        8 * 1024
  341. uchar buf [MAXBUF];
  342.  
  343. char *tegettext (TEXTEDIT *tp)
  344. {
  345.     Handle    th;
  346.     short    i, j;
  347.     long    maxText;
  348.     
  349.     maxText = ((CTextPane *)tp)->GetLength ();
  350.     
  351.     th = ((CTextPane *)tp)->GetTextHandle ();
  352.     if (maxText > MAXBUF - 1)
  353.         maxText = MAXBUF - 1;
  354.         
  355.     BlockMove (*th, buf, maxText);
  356.     buf [maxText] = '\0';
  357.         
  358.     return (char *)buf;
  359. }
  360.  
  361.  
  362. //===================================================================================
  363. // Return the text inside the selected area (if there is any)
  364. // Not a StdWin function.
  365. //===================================================================================
  366. char *teGetSelectedText (TEXTEDIT *tp)
  367. {
  368.     long    selStart, selEnd;
  369.     short    i;
  370.     char     *cp;
  371.     
  372.     cp = (char *)*(((CTextPane *)tp)->GetTextHandle ());
  373.     ((CTextPane *)tp)->GetSelection (&selStart, &selEnd);
  374.  
  375.     if (selEnd <= selStart) {
  376.         buf [0] = '\0';
  377.         return (char *)buf;
  378.     }
  379.     
  380.     for (i = 0; i < MAXBUF; i++) {
  381.         if (selStart == selEnd)
  382.             break;
  383.         buf [i] = cp [selStart++];
  384.     } 
  385.     buf [i] = '\0';
  386.     return (char *)buf;
  387. }
  388.  
  389.  
  390. //===================================================================================
  391. // Draw the contents of the given TextEdit.
  392. //===================================================================================
  393. void tedraw (register TEXTEDIT *tp)
  394. {
  395.     Rect        area;
  396.     LongRect    lr, margin = {0, 0, 0, 0};
  397.     
  398.     ((CTextPane *)tp)->GetAperture  (&lr);
  399.     ((CTextPane *)tp)->FrameToQDR   (&lr, &area);
  400.     ((CTextPane *)tp)->Draw         (&area);
  401. }
  402.  
  403.  
  404. //===================================================================================
  405. // Save the text of a TextEdit to the given file. Not a StdWin function.
  406. //===================================================================================
  407. void saveTE (TEXTEDIT *tp, short fileNum)
  408. {
  409.     CDataFile        *fil;
  410.     FILE            *fd;
  411.     CharsHandle        teh;
  412.     
  413.     teh = TEGetText (((CTextPane *)tp)->macTE);
  414.     
  415.     fil  = new (CDataFile);
  416.     fil->IDataFile ();
  417.     fd   = getFilePointer (fileNum);
  418.     fil->refNum = fd->fileRef;
  419.     fil->WriteAll ((Handle)teh);
  420. }
  421.  
  422.  
  423. //===================================================================================
  424. // Load the text of a TextEdit from the given file. Not a StdWin function.
  425. //===================================================================================
  426. void loadTE (TEXTEDIT *tp, short fileNum)
  427. {
  428.     CDataFile    *fil;
  429.     FILE        *fd;
  430.     Handle        hndl;
  431.     
  432.     fil  = new (CDataFile);
  433.     fil->IDataFile ();
  434.     fd   = getFilePointer (fileNum);
  435.     fil->refNum = fd->fileRef;
  436.     hndl = fil->ReadAll ();
  437.     ((CTextPane *)tp)->ReplaceContents ((char *)*hndl);
  438.     ((CTextPane *)tp)->AdjustBounds ();
  439. }
  440.  
  441.  
  442. //===================================================================================
  443. // Send an Open Document AppleEvent to the specified app using the specified file.
  444. // Not a StdWin function.
  445. //===================================================================================
  446. OSErr sendOpenDocEvent (long theAppSig, SFReply *theSFReply)
  447. {
  448.     AppleEvent        aEvent;
  449.     FSSpec            theFile;
  450.     WDPBRec            wdInfo;
  451.     OSErr            err;
  452.     AEDescList        docList;
  453.     AEDesc            docDesc, sigDesc;
  454.     AERecord        aeRec;
  455.     Boolean            disposeCheck [4] = {FALSE, FALSE, FALSE, FALSE};
  456.  
  457.     err = AECreateDesc   (typeApplSignature, &theAppSig, (Size)sizeof(long), 
  458.                            &sigDesc);
  459.     if (err)
  460.         goto sendOpenDocEvent_exit;
  461.         
  462.     disposeCheck [0] = TRUE;
  463.     err = AECreateAppleEvent (kCoreEventClass, kAEOpenDocuments, &sigDesc, 
  464.                               kAutoGenerateReturnID, kAnyTransactionID, &aEvent);
  465.     if (err)
  466.         goto sendOpenDocEvent_exit;
  467.         
  468.     disposeCheck [1] = TRUE;
  469.     wdInfo.ioNamePtr  = NULL;                    // Convert SFReply to FSSpec
  470.     wdInfo.ioVRefNum  = theSFReply->vRefNum;
  471.     wdInfo.ioWDIndex  = 0;
  472.     wdInfo.ioWDProcID = 0;
  473.     err = PBGetWDInfo (&wdInfo, FALSE);
  474.     if (err)
  475.         goto sendOpenDocEvent_exit;
  476.         
  477.     theFile.vRefNum  = wdInfo.ioWDVRefNum;
  478.     theFile.parID    = wdInfo.ioWDDirID;
  479.     BlockMove (theSFReply->fName, theFile.name, (long)theSFReply->fName [0] + 1);
  480.     
  481.     err = AECreateList (NULL, 0, FALSE, &docList);
  482.     if (err)
  483.         goto sendOpenDocEvent_exit;
  484.  
  485.     disposeCheck [2] = TRUE;
  486.     err = AECreateDesc (typeFSS, &theFile, (Size)sizeof (FSSpec), &docDesc);
  487.     if (err)
  488.         goto sendOpenDocEvent_exit;
  489.  
  490.     disposeCheck [3] = TRUE;
  491.     err = AEPutDesc (&docList, 0L, &docDesc);
  492.     if (err)
  493.         goto sendOpenDocEvent_exit;
  494.  
  495.     err = AEPutParamDesc (&aEvent, keyDirectObject, &docList);
  496.     if (err)
  497.         goto sendOpenDocEvent_exit;
  498.  
  499.     err = AESend (&aEvent, NULL, kAENoReply + kAEAlwaysInteract + kAECanSwitchLayer,
  500.                   kAENormalPriority, kAEDefaultTimeout, NULL, NULL);
  501.                   
  502. sendOpenDocEvent_exit:
  503.     if (disposeCheck [1])
  504.         AEDisposeDesc (&aEvent);
  505.     if (disposeCheck [2])
  506.         AEDisposeDesc (&docList);
  507.     if (disposeCheck [3])
  508.         AEDisposeDesc (&docDesc);
  509.     if (err)
  510.         return err;
  511.         
  512.     return 0L;
  513. }
  514.  
  515.  
  516. //===================================================================================
  517. // Translate the info provided after an Open Document event has been received into
  518. // the full path and file type that Smalltalk currently likes. (I really will have
  519. // to get Smalltalk used to dealing with directory IDs one of these days...) Return
  520. // FALSE if info not present.
  521. //
  522. // Not a StdWin function.
  523. //===================================================================================
  524. Boolean getFileInfo (char *fullPath, long *fType)
  525. {
  526.     if (gSmalltalk->theFile.fType == 0L)
  527.         return FALSE;
  528.         
  529.     *fType = (long)gSmalltalk->theFile.fType;
  530.     getPathNameFromWD ((long)gSmalltalk->theFile.vRefNum, fullPath);
  531.     PtoCstr     (gSmalltalk->theFile.fName);
  532.     strcat      (fullPath, (char *)gSmalltalk->theFile.fName);
  533.     CtoPstr     ((char *)gSmalltalk->theFile.fName);
  534.     return TRUE;
  535. }
  536.  
  537.  
  538. //===================================================================================
  539. // Process any AppleEvents sent by the Finder when the application is first launched.
  540. // I handle these separately from other events so I can load a system image before
  541. // Smalltalk itself is started. 
  542. //
  543. // Only HighLevelEvents are processed; anything else is ignored.
  544. //
  545. // Not a StdWin function.
  546. //===================================================================================
  547. Boolean processStartUpEvent (char *buf)
  548. {
  549.     EventRecord        event;
  550.     long            fType;
  551.     short            i = 255;
  552.     OSErr            err;
  553.  
  554.     while (i) {
  555.         if (WaitNextEvent (highLevelEventMask, &event, 0, NULL) ) {
  556.             if (AEProcessAppleEvent (&event))
  557.                 return FALSE;                        // Error case.
  558.                 
  559.             if (getFileInfo (buf, &fType)) {
  560.                 if (fType == kSysImageType)
  561.                     return TRUE;
  562.                 else {        // Not a sys. image so requeue Event for handling later
  563.                     err = sendOpenDocEvent (kCreator, &gSmalltalk->theFile);
  564.                     return FALSE;
  565.                 }
  566.             }
  567.         }
  568.         i--;
  569.     }
  570. }
  571.  
  572.  
  573. //===================================================================================
  574. // Get a user event from the system and translate it into StdWin format.
  575. //===================================================================================
  576. Point    lastMouse = {-32767, -32767};
  577.  
  578. void wgetevent (EVENT *ep)
  579. {
  580.      EventRecord    *macEvent;
  581.      Point        wp;
  582.     char        theChar;
  583.     Byte        keyCode;
  584.     WindowPtr    w;
  585.  
  586.      gSmalltalk->lastEvent.what = 0;
  587.      gSmalltalk->theFile.fType  = 0L;
  588.      
  589.      gSmalltalk->Process1Event ();
  590.      if (gSmalltalk->menuID == 0xffff) {
  591.          ep->type = WE_QUIT;
  592.          return;
  593.      }
  594.      if (gSmalltalk->lastEvent.what == 0) {
  595.          ep->type = WE_NULL;
  596.         return;
  597.     }
  598.          
  599.      macEvent = &(gSmalltalk->lastEvent);
  600.     
  601.     wp = macEvent->where;
  602.     GlobalToLocal (&wp);
  603.     if (lastMouse.h == -32767 && lastMouse.v == -32767)
  604.         lastMouse = wp;
  605.  
  606.         
  607.     w = FrontWindow ();
  608.     if (w)
  609.         ep->window = ((CLStWindow *)GetWRefCon (w))->theLStWindow;
  610.     else
  611.         ep->window = NULL;
  612.         
  613.     switch (macEvent->what) {
  614.         case mouseDown:
  615.             processMouseDown (macEvent, ep);
  616.             break;
  617.         case mouseUp:
  618.             ep->type = WE_MOUSE_UP;
  619.             ep->u.where.h      = wp.h;
  620.             ep->u.where.v      = wp.v;
  621.             ep->u.where.clicks = 1;
  622.             ep->u.where.button = 1;
  623.             ep->u.where.mask   = 0;
  624.             break;
  625.         case keyDown:
  626.         case autoKey:
  627.             theChar = macEvent->message & charCodeMask;
  628.             keyCode = (macEvent->message & keyCodeMask) >> 8;
  629.             if (macEvent->modifiers & cmdKey)
  630.                 break;
  631.             switch (keyCode) {
  632.                 case kEscapeOrClear:
  633.                 case kLeftCursor:
  634.                 case kRightCursor:
  635.                 case kUpCursor:
  636.                 case kDownCursor:
  637.                 case KeyHome:
  638.                 case KeyEnd:
  639.                 case KeyPageUp:
  640.                 case KeyPageDown:
  641.                 case KeyEscape:
  642.                 case KeyClear:
  643.                 case KeyHelp:
  644.                 case KeyFwdDelete:
  645.                 case KeyF1:
  646.                 case KeyF2:
  647.                 case KeyF3:
  648.                 case KeyF4:
  649.                 case KeyF5:
  650.                 case KeyF6:
  651.                 case KeyF7:
  652.                 case KeyF8:
  653.                 case KeyF9:
  654.                 case KeyF10:
  655.                 case KeyF11:
  656.                 case KeyF12:
  657.                 case KeyF13:
  658.                 case KeyF14:
  659.                 case KeyF15:
  660.                     ep->type       = WE_KEY;
  661.                     ep->u.key.code = keyCode;
  662.                     ep->u.key.mask = WM_META;
  663.                     break;
  664.                 case KeyLeftCursor:
  665.                 case KeyRightCursor:
  666.                 case KeyUpCursor:
  667.                 case KeyDownCursor:
  668.                     ep->type      = WE_COMMAND;
  669.                     ep->u.command = WC_LEFT;
  670.                     break;
  671.                 case kEnterKey:
  672.                     ep->type      = WE_COMMAND;
  673.                     ep->u.command = WC_RETURN;
  674.                     break;
  675.                 default:
  676.                     ep->type        = WE_CHAR;
  677.                     ep->u.character = theChar;
  678.             }
  679.             break;
  680.         case updateEvt:
  681.             {
  682.              WindowPtr    w = FrontWindow ();
  683.             Rect         r = (**(((WindowRecord *)w)->updateRgn)).rgnBBox;
  684.              
  685.             ep->type          = WE_DRAW;
  686.             ep->u.area.left   = r.left;
  687.             ep->u.area.top    = r.top;
  688.             ep->u.area.right  = r.right;
  689.             ep->u.area.bottom = r.bottom;
  690.             break;
  691.             }
  692.         case activateEvt:
  693.             ep->type = WE_ACTIVATE;
  694.             break;
  695.         case kHighLevelEvent:            /* Process AppleEvent */
  696.              ep->type = WE_EXTERN;
  697.             break;
  698.         default:
  699.             if (   (wp.h != lastMouse.h) 
  700.                 || (wp.v != lastMouse.v) ) {
  701.                 ep->type           = WE_MOUSE_MOVE;
  702.                 ep->u.where.h      = wp.h;
  703.                 ep->u.where.v      = wp.v;
  704.                 lastMouse          = wp;
  705.                 ep->u.where.clicks = gClicks;
  706.                 ep->u.where.button = 1;
  707.                 ep->u.where.mask   = 0;
  708.             }
  709.             else
  710.                 ep->type = WE_NULL;
  711.     }
  712.     lastMouse = wp;
  713. }
  714.  
  715.  
  716. //===================================================================================
  717. // Special processing for mouseDown events. Not a StdWin function.
  718. //===================================================================================
  719. void processMouseDown (EventRecord *macEvent, EVENT *ep)
  720. {    
  721.     if (gSmalltalk->winPart != inContent && gSmalltalk->winPart == inSysWindow)
  722.         return;
  723.         
  724.     switch (gSmalltalk->winPart) {
  725.         case inMenuBar:
  726.             ep->type     = WE_MENU;
  727.             if (gSmalltalk->menuID > kSTMenuBase) {
  728.                 ep->u.m.id   = gSmalltalk->menuID   - kSTMenuBase;
  729.                 ep->u.m.item = gSmalltalk->menuItem - 1; 
  730.             }
  731.             else {
  732.                 ep->type     = WE_NULL;
  733.                 ep->u.m.id   = 0; 
  734.                 ep->u.m.item = 0;
  735.             }
  736.             break;
  737.         case inDrag:
  738.             ep->type = WE_MOVE;
  739.             break;
  740.         case inGrow:
  741.             ep->type = WE_SIZE;
  742.             break;
  743.         case inGoAway:
  744.             ep->type = WE_CLOSE;
  745.             break;
  746.         default:
  747.         {
  748.             WINDOW        *w;
  749.             GrafPtr        aPort;
  750.             
  751.             ep->type           = WE_MOUSE_DOWN;
  752.             if (ep->window != NULL)
  753.                 ((CLStWindow *)(ep->window->window))->Prepare ();
  754.             GlobalToLocal (&(macEvent->where));        // Return point in _window_ co-ords.
  755.             ep->u.where.h      = macEvent->where.h;
  756.             ep->u.where.v      = macEvent->where.v;
  757.             ep->u.where.clicks = gClicks;
  758.             if (macEvent->modifiers & optionKey)
  759.                 ep->u.where.button = 2;        // Simulate a 2 button mouse with help of 'option' key
  760.             else
  761.                 ep->u.where.button = 1;
  762.             ep->u.where.mask   = 0;
  763.         }
  764.     }
  765. }
  766.  
  767.  
  768. //===================================================================================
  769. // Stub function provided for StdWin compatibility.
  770. //===================================================================================
  771. void wsettimer (WINDOW *win, int deciseconds)
  772. {
  773.     return;
  774. }
  775.  
  776.  
  777.